Repository navigation
fix(sync): Webull trade history without phantom positions - #56
Merged
Merged
Conversation
broker-sdk now reads Webull's order history (a year of it). Journaling that history needs three things the journal didn't do. - Fills that reach back before the start of a broker's history are handled in a pure step, keepWithinHistory. A close with nothing open is dropped. A close bigger than what the history opened keeps the part the history covers. For unlabeled fills, Webull's complete equity position list decides which fill opened a position that never existed. The kept part of a fill hashes with the broker's quantity (hashQuantity), so later syncs still match it. - Options that expired while held close at 0 at the 4pm New York expiry. Webull records no fill for an expiry, so they otherwise stay open forever. - Broker-stated option contract sizes are saved as multipliers unless the user set one, and synced fills keep the broker's asset class. - Later syncs pass historySince (the last sync less 30 days), so only recent orders are fetched. Replaces #29; thanks to @anthony-som for the proposal.
0.6.0 adds Webull order history and the trade fields this branch uses (LuxAlgo/broker-sdk#24), plus Binance USDⓈ-M futures (LuxAlgo/broker-sdk#25).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Webull sync now imports trade history without inventing positions, using broker-sdk 0.6.0 (#28). It replaces #29 with our own implementation.
Cause
broker-sdk 0.6.0 reads a year of Webull order history (LuxAlgo/broker-sdk#24). Once that history arrives, the journal shows three problems, all reported by @anthony-som in #28:
Fix
keepWithinHistoryinapps/web/src/server/broker-history.tsis a pure step that decides how much of each new fill to keep.hashQuantity), so later syncs still match it.historySince, the last sync less 30 days, so only recent orders are fetched. On the test account in Webull sync: connection fails, no trades import, and synced history creates phantom positions #28 that brought a repeat sync from about 75s down to about 1s.Limits, noted in code:
Test
apps/web/tests/broker-history.test.tshas unit tests for:apps/web/tests/webull-sync-flow.test.tsrunssyncAccountwith broker-sdk's Webull adapter against a stubbed gateway. It covers:Checks run locally
All of these pass:
pnpm format:check,pnpm typecheck,pnpm test(70 files, 658 tests),node scripts/check-licenses.mjs,pnpm -r --filter "./packages/*" buildandpnpm build.Fixes #28